package com.study

import org.apache.flink.streaming.api.scala.StreamExecutionEnvironment
import org.joda.time.DateTime


object FlinkStreamWordCount {
  def main(args: Array[String]): Unit = {
    println("当前时间是：", new DateTime().toString("yyy-MM-dd'T'HH:mm:ss"))
    //    1 初始化流计算环境
    val environment = StreamExecutionEnvironment.getExecutionEnvironment

    //    2 导入隐式转换
    import org.apache.flink.streaming.api.scala._
    //    3 读取数据
    val stream = environment.socketTextStream("192.168.226.121", 8888)

    //    4 转换和处理数据
    val result = stream.flatMap(_.split(" ")).map((_, 1)).keyBy(0).sum(1)

    //    5 打印结果
    result.print("结果")

    //    6 启动流计算程序
    environment.execute("wordCountDemo|示例")

  }
}
